<template>
<Card>
	<p slot="title">常规设置</p>

	<Form v-if="showPage" :label-width="100">
		<FormItem label="购买权限" prop="shoppingVisibleType">
			<RadioGroup v-model="model.shoppingVisibleType">
				<Radio :label="1" :disabled="!isEditing">所有人可见</Radio>
				<Radio :label="2" :disabled="!isEditing">会员可见</Radio>
			</RadioGroup>
		</FormItem>
		<FormItem label="库存扣减" prop="inventoryDeductionType">
			<RadioGroup v-model="model.inventoryDeductionType">
				<Radio :label="1" :disabled="!isEditing">付款减库存</Radio>
				<Radio :label="2" :disabled="!isEditing">下单减库存</Radio>
			</RadioGroup>
			<Tooltip max-width="500" placement="暂无">
				<Icon type="ios-information-circle-outline" pd2 sz3/>
				<div slot="content">
					<p>付款减库存：买家付款减库存，存在超卖风险。</p>
					<p>下单减库存：买家拍下减库存，存在恶拍风险。</p>
					<p>建议举办营销活动时选择下单减库存，避免超卖。</p>
				</div>
			</Tooltip>
		</FormItem>
		<FormItem>
			<Button v-if="!isEditing" type="primary" @click="handleEdit">修改</Button>
			<Button v-if="isEditing" type="primary" @click="handleSave" mgr2>保存</Button>
			<Button v-if="isEditing" @click="handleCancel">取消</Button>
		</FormItem>
	</Form>
</Card>
</template>

<script lang="ts">
import { Component, Vue,Inject, Prop,Watch } from 'vue-property-decorator';
import AbpBase from '../../../lib/abpbase';

@Component({
	components: {}
})
export default class ShipSetting extends AbpBase{
	model:any = {
		shoppingVisibleType: 1,
		inventoryDeductionType: 1
	}
	handleEdit() {
		this.isEditing = true;
	}
	async handleSave() {
		await this.setData();
		this.isEditing = false;
	}
	async handleCancel() {
		await this.getData();
		this.isEditing = false;
	}
	async getData() {
		var response = await this.get('Setting/GetMallGeneralSetting');
		if(response.success) {
			this.model = response.result;
		}
	}
	async setData() {
		var response = await this.post('Setting/SetMallGeneralSetting', this.model);
		if(response.success) {
			this.success('保存成功');
		}
	}
	async created() {
		this.showPage = false;
		await this.getData();
		this.showPage = true;
	}
}
</script>